package com.nidu.demo.mail.executor.query;

import com.alibaba.cola.dto.MultiResponse;
import com.nidu.demo.mail.convertor.MailTemplateConvertor;
import com.nidu.demo.mail.convertor.MailTemplateCriteriaConvertor;
import com.nidu.demo.mail.dto.MailTemplateCO;
import com.nidu.demo.mail.dto.MailTemplateListQry;
import com.nidu.demo.mail.gateway.MailTemplateGateway;
import com.nidu.demo.mail.model.MailTemplate;

import com.nidu.demo.mail.model.MailTemplateCriteria;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 邮件模板列表查询执行器
 *
 * @author auto
 */
@Component
@RequiredArgsConstructor
public class MailTemplateListQryExe {

    private final MailTemplateCriteriaConvertor criteriaConvertor;
    private final MailTemplateGateway gateway;
    private final MailTemplateConvertor convertor;

    public MultiResponse<MailTemplateCO> execute(MailTemplateListQry qry) {
        MailTemplateCriteria criteria = criteriaConvertor.toDataObject(qry);
        List<MailTemplate> templates = gateway.listByCondition(criteria);
        List<MailTemplateCO> templateCOS = convertor.toClientObjects(templates);
        return MultiResponse.of(templateCOS);
    }

}
